package com.demo.jsf;

import java.util.Hashtable;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;

public abstract class BaseAction {

	protected LoginAction loginAction;
	protected SelectItemGroup pageSizeItems = new SelectItemGroup();// 页大小下拉选项
	protected SelectItemGroup pageNoItems = new SelectItemGroup();// 跳页下拉选项
	protected int pageSize = 5;// 页大小
	protected int pageNo = 1;// 页码
	protected int rowCount;// 总行数
	protected int pageCount;// 总页数
	protected int pageFirstNo;// 首页
	protected int pageLastNo;// 尾页
	protected int pagePreNo;// 前一页
	protected int pageNextNo;// 后一页
	protected List<Hashtable<String, String>> list;// 数据列表

	public LoginAction getLoginAction() {
		return loginAction;
	}

	public void setLoginAction(LoginAction loginAction) {
		this.loginAction = loginAction;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageFirstNo() {
		return pageFirstNo;
	}

	public void setPageFirstNo(int pageFirstNo) {
		this.pageFirstNo = pageFirstNo;
	}

	public int getPageLastNo() {
		return pageLastNo;
	}

	public void setPageLastNo(int pageLastNo) {
		this.pageLastNo = pageLastNo;
	}

	public int getPagePreNo() {
		return pagePreNo;
	}

	public void setPagePreNo(int pagePreNo) {
		this.pagePreNo = pagePreNo;
	}

	public int getPageNextNo() {
		return pageNextNo;
	}

	public void setPageNextNo(int pageNextNo) {
		this.pageNextNo = pageNextNo;
	}

	public List<Hashtable<String, String>> getList() {
		return list;
	}

	public void setList(List<Hashtable<String, String>> list) {
		this.list = list;
	}

	public SelectItemGroup getPageSizeItems() {
		SelectItem[] selectItems = new SelectItem[7];
		selectItems[0] = new SelectItem(10);
		selectItems[1] = new SelectItem(25);
		selectItems[2] = new SelectItem(50);
		selectItems[3] = new SelectItem(100);
		selectItems[4] = new SelectItem(200);
		selectItems[5] = new SelectItem(300);
		selectItems[6] = new SelectItem(500);
		pageSizeItems.setSelectItems(selectItems);
		return pageSizeItems;
	}

	public SelectItemGroup getPageNoItems() {
		SelectItem[] selectItems = new SelectItem[pageCount];
		for (int i = 0; i < pageCount; i++) {
			selectItems[i] = new SelectItem(i + 1);
		}
		pageNoItems.setSelectItems(selectItems);
		return pageNoItems;
	}
	
	public String list() {
		return "welcome";
	}
	
	public void changePageSize(ValueChangeEvent event) {
		String strPageSize = event.getNewValue().toString();
		pageSize = Integer.valueOf(strPageSize);
		list();
	}

	public void changePageNo(ValueChangeEvent event) {
		String strPageNo = event.getNewValue().toString();
		pageNo = Integer.valueOf(strPageNo);
		list();
	}
}
